import { defineConfig } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";
import commonjs from "@rollup/plugin-commonjs";
export default defineConfig({
  base: "./",
  publicDir: false, //是否拷贝公共资源目录的文件(默认:public)
  build: {
    outDir: "public/lib",
    emptyOutDir: false, //构建前是否清空outDir
    cssCodeSplit: true, //是否拆分css,lib模式永远抽离到单独的css文件内
    lib: {
      entry: path.resolve(__dirname, "src/application/Application.vue"),
      name: "Application",
      fileName: "Application"
      // cssCodeSplit: false
      // fileName: (format) => `visual-sdk/VisualAppLib.${format}.js`
    },
    rollupOptions: {
      external: ["vue", "vue-router", "element-plus"], //排除不需要打包的依赖包
      output: {
        assetFileNames: (assetInfo) => {
          // console.log("assetInfo", assetInfo);
          return "[name][extname]";
        },
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: { vue: "Vue", "element-plus": "ElementPlus" }
      }
    }
  },

  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src")
    },
    extensions: [".js", ".vue", ".json", ".ts"] // 使用路径别名时想要省略的后缀名，可以自己 增减
  },
  // css: {move
  //   preprocessorOptions: {
  //     scss: {
  //       additionalData: `@use "~/styles/element/index.scss" as *;`,
  //     },
  //   },
  // },
  define: { "process.env": {} }, //去除编译后process报错的问题
  plugins: [
    vue(),
    commonjs({ requireReturnsDefault: true }) // 配置requireReturnsDefault属性，//解决引入commonjs模块后打包出现的{'default' is not exported by XXX}错误!!
  ]
});
